package com.zy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.bean.bo.project.ProjectCreateBo;
import com.zy.bean.bo.project.ProjectUpdateBo;
import com.zy.bean.po.ProjectRecords;
import com.zy.bean.qo.ProjectSearchQo;
import com.zy.bean.vo.ProjectRecordsVo;
import com.zy.service.ProjectRecordsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 项目相关的接口
 *
 * @author hanhuafeng
 * @version V1.0
 * @description
 * @date 2023/7/18
 */
@RestController
@RequestMapping("/v1/project")
@RequiredArgsConstructor
public class ProjectController {
    private final ProjectRecordsService projectRecordsService;

    /**
     * 创建项目
     *
     * @param projectCreateBo 项目创建bo
     */
    @PostMapping
    public ProjectRecords createProject(@RequestBody ProjectCreateBo projectCreateBo) {
        return projectRecordsService.createProjectRecords(projectCreateBo);
    }

    /**
     * 分页获取项目列表
     *
     * @param qo 查询条件
     * @return Page<ProjectRecordsVo>
     */
    @GetMapping
    public Page<ProjectRecordsVo> getProjectRecords(ProjectSearchQo qo) {
        return projectRecordsService.getProjectRecordsByPage(qo);
    }

    /**
     * 根据项目code修改项目信息
     *
     * @param projectUpdateBo 项目修改bo
     * @return ProjectRecords
     */
    @PatchMapping("/{projectCode}")
    public ProjectRecords updateProject(@PathVariable String projectCode,
                                        @RequestBody ProjectUpdateBo projectUpdateBo) {
        return projectRecordsService.updateProjectRecords(projectCode, projectUpdateBo);
    }

    /**
     * 根据项目code删除项目
     *
     * @param projectCode 项目code
     */
    @DeleteMapping("/{projectCode}")
    public void deleteProject(@PathVariable String projectCode) {
        projectRecordsService.deleteProject(projectCode);
    }


    /**
     * 根据项目code获取项目信息
     *
     * @param projectCode 项目code
     * @return ProjectRecordsVo 项目信息
     */
    @GetMapping("/{projectCode}")
    public ProjectRecordsVo getProjectRecordsByCode(@PathVariable String projectCode) {
        return projectRecordsService.getProjectRecordsByCode(projectCode);
    }
}
